﻿using UnityEngine;
using System.Collections;

namespace AutoRoot
{
   public class ControlPart : MonoBehaviour
   {
      public GameObject[] gameObjectsOfPlaySection;
      public GameObject[] gameObjectsOfPlayDecision;

      public bool playingSection = true;

      void OnPlaySection()
      {
         playingSection = true;
         SetGameObjectActivity(gameObjectsOfPlayDecision, false, gameObjectsOfPlayDecision.Length);
         SetGameObjectActivity(gameObjectsOfPlaySection, true, gameObjectsOfPlaySection.Length);
      }

      void OnPlayDecision(int options)
      {
         playingSection = false;
         SetGameObjectActivity(gameObjectsOfPlaySection, false, gameObjectsOfPlaySection.Length);
         SetGameObjectActivity(gameObjectsOfPlayDecision, false, gameObjectsOfPlayDecision.Length);
         SetGameObjectActivity(gameObjectsOfPlayDecision, true, options);
         gameObjectsOfPlayDecision[gameObjectsOfPlayDecision.Length - 1].SetActive(true);
      }

      void SetGameObjectActivity(GameObject[] gameObjects, bool active, int amount)
      {
         print(amount);
         for (int count = 0; (count < amount) && (count < gameObjects.Length); ++count)
         {
            print(count + "/" + gameObjects[count].name + "/" + active);
            gameObjects[count].SetActive(active);
         }
      }
   }
}